﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sworm
{
    class RecordTracker
    {
        private readonly Dictionary<Type, Dictionary<object, object>> dict
            = new Dictionary<Type, Dictionary<object, object>>();

        public object TryGet(Type type, object pk)
        {
            Dictionary<object, object> d;
            if (!dict.TryGetValue(type, out d))
            {
                return null;
            }

            object entity;
            if (!d.TryGetValue(pk, out entity))
            {
                return null;
            }

            return entity;
        }

        public void Put(Type type, object pk, object instance)
        {
            Dictionary<object, object> d;
            if (!dict.TryGetValue(type, out d))
            {
                d = new Dictionary<object, object>();
                dict[type] = d;
            }

            d[pk] = instance;
        }
    }
}
